package zb.WX.service.userManage;

import com.google.gson.Gson;
import zb.WX.bean.userManage.BlackList;
import zb.WX.util.AccessTokenSaveUtil;
import zb.WX.util.GlobalVar;
import zb.WX.util.HttpsUtil;

import java.util.ArrayList;
import java.util.List;

public class BackListService {
    /*
     * 拉黑用户：
     */
    public String setBackList(List<String> opened_list) {
        String access_token = AccessTokenSaveUtil.getLocationAccesstonken();
        String urlStr = GlobalVar.SET_BLACK_LIST.replace("ACCESS_TOKEN", access_token);

        BlackList blackList = new BlackList();
        blackList.setOpened_list(opened_list);

        Gson gson = new Gson();
        String jsonStr = gson.toJson(blackList);
        System.out.println("设置黑名单：" + jsonStr);

        String result = HttpsUtil.getHttpsToJson(urlStr, jsonStr);
        System.out.println("设置黑名单返回结果：" + result);

        return result;
    }

    /*
     * 获取黑名单列表：
     */
    public String getBackList(String beginOpenId) {
        String access_token = AccessTokenSaveUtil.getLocationAccesstonken();
        String urlStr = GlobalVar.GET_BLACK_LIST.replace("ACCESS_TOKEN", access_token);

        BlackList blackList = new BlackList();
        blackList.setBegin_openid(beginOpenId);

        Gson gson = new Gson();
        String jsonStr = gson.toJson(blackList);
        System.out.println("拉取黑名单：" + jsonStr);

        String result = HttpsUtil.getHttpsToJson(urlStr, jsonStr);
        System.out.println("拉取黑名单返回结果：" + result);

        return null;
    }

    /*
     * 取消拉黑的用户：
     *
     */

    public String cancleBlackList(List<String> opened_list) {
        String access_token = AccessTokenSaveUtil.getLocationAccesstonken();
        String urlStr = GlobalVar.CANCLE_BLACK_LIST.replace("ACCESS_TOKEN", access_token);

        BlackList blackList = new BlackList();
        blackList.setOpened_list(opened_list);

        Gson gson = new Gson();
        String jsonStr = gson.toJson(blackList);
        System.out.println("取消黑名单：" + jsonStr);

        String result = HttpsUtil.getHttpsToJson(urlStr, jsonStr);
        System.out.println("取消黑名单返回结果：" + result);

        return result;
    }


    public static void main(String[] args) {
        //设置黑名单
        List<String> opened_list = new ArrayList<String>();
        opened_list.add("o2joUxCBE7e4prl1vLk87oMXEieU");
        new BackListService().setBackList(opened_list);


        //查询给名单
        new BackListService().getBackList("");//默认从头开始拉取

        //取消黑名单
		/*List<String> opened_list = new ArrayList<String>();
		opened_list.add("o2joUxKYEB0Tg-pcUEyCaglOhnYk");
		new BackListService().cancleBlackList(opened_list);*/
    }
}
